#include "Serialize.h"
#include <cstring>

void Serialize(std::ostream & os, const std::string &val)
{
	size_t size = val.size();
	os.write((const char *)&size, sizeof(size));
	os.write((const char *)val.data(), size * sizeof(typename std::string::value_type));
}

void Serialize(std::ostream & os, const char* pszVal)
{
	size_t size = strlen(pszVal);
	os.write((const char *)&size, sizeof(size));
	os.write((const char *)pszVal, size * sizeof(char));
}

void Deserialize(std::istream & is, std::string &val)
{
	size_t size = 0; 
	is.read((char*)&size, sizeof(size_t));
	val.resize(size);
	auto count = size * sizeof(typename std::string::value_type);
	is.read((char *)val.data(), count);
}